<? include("/inc/header.html") {} ?>

<div class="col-lg-12">
	<div class="panel panel">
		<div class="panel-body pan" style="height: 180px">
			<div class="form-body pal">
				<div>
					<label for="inputUsername" class="col-md-3 control-label">栏目名称(只允许汉字、英文字母、数字及下划线,20个字符以内) <span
						class='require'>*</span></label>
					<div class="col-md-9">
						<div class="input-icon">
							<input id="name" type="text" class="form-control" value="${category.name}" autocomplete="off"/>
						</div>
					</div>
				</div>
				<div>
					<label for="inputUsername" class="col-md-3 control-label">栏目排序(1-10000之间的整数)
						<span class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<input id="sort" type="text" class="form-control" value="${category.sort}" autocomplete="off"/>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<input id="id" type="hidden" class="form-control" value="${category.id}"/>
</div>
<script>
function save(){


	var name=$("#name").val(); //    
    var re =/^[\u4e00-\u9fa5_a-zA-Z0-9]{1,20}$/;
	if (!re.test(name)) {
		layer.msg('栏目名称:只允许汉字、英文字母、数字及下划线,限制20个字符以内。');
		return null;
	}


	

	var text=$("#sort").val(); //    
    var re =/^[1-9]*[1-9][0-9]*$/;
	if (!re.test(text)) {
		layer.msg('排序:输入在1-10000之间的整数！');
		return null;
	}
	var num = parseInt(text);
	if(num>10000 || num<1){
		layer.msg('排序:输入在1-10000之间的整数！');
		return null;
	}

	$.ajax({
		type : "post",
		url : "./categoryAddUpdate.do",
		data : {
			"id" : $("#id").val(),
			"name" : $("#name").val(),
			"sort" : $("#sort").val()
		},
		dataType : "json",
		success : function(data) {
			if(data[0].result == 'success'){
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.get();
				parent.layer.msg('提交成功');
				parent.layer.close(index);
			}else{
				parent.layer.msg(data[0].msg);
			}
		},
		error : function(data) {
			alert("请求失败");
		}
	});
}
	
</script>